<?php
/**
 * session适配器
 * @author Yuwei(yuwei1122@gmail.com)
 */
class BluePhp_Library_Session_Adapter
{
	/**
	 * 初始化
	 */
	public static function _initialization()
	{
		session_write_close();
		session_module_name('user');
		switch (SESS_HANDLER)
		{
			case 'file':
				$drive = new BluePhp_Library_Session_Drives_File();
			break;
			case 'memcache':
			default:
				$drive = new BluePhp_Library_Session_Drives_Memcache();
			break;
		}
		session_set_save_handler
		(
			array($drive,'open'),
			array($drive,'close'),
			array($drive,'read'),
			array($drive,'write'),
			array($drive,'destroy'),
			array($drive,'gc')
		);
// 		$sid = BluePhp_Library_Input_Adapter::get('PHPSESSID')?BluePhp_Library_Input_Adapter::get('PHPSESSID'):BluePhp_Library_Cookie_Adapter::get('PHPSESSID');
// 		session_id($sid);
		session_start();
	}
	
	/**
	 * 读出
	 * @param unknown_type $key
	 */
	public static function get($key = '')
	{
		if($key)
			return isset($_SESSION[$key])?$_SESSION[$key]:'';
		else
			return $_SESSION;
	}
	
	/**
	 * 写入
	 * @param unknown_type $key
	 * @param unknown_type $value
	 */
	public static function set($key,$value)
	{
		$_SESSION[$key] = $value;
	}
}
?>